// Symbol的使用
let hd = Symbol("后盾人在线教程");
let edu = Symbol("网址是houdunren.com");
console.log(hd == edu); // false
console.log(hd.description); // Symbol传入的值

let cms = Symbol.for("hdcms");
console.log(Symbol.keyFor(cms)); // 只有用for定义的才可以用keyfor拿到

let user1 = {
  name: "李四",
  key: Symbol(),
};

let user2 = {
  name: "李四",
  key: Symbol(),
};

// 当出现了两个一摸一样的key值时候可以使用Symbol定义
let grade = {
  [user1.key]: { js: 100, css: 89 },
  [user2.key]: { js: 33, css: 55 },
};

console.log(grade[user1.key]);

class Cache {
  static data = {};
  static set(name, value) {
    return (this.data[name] = value);
  }
  static get(name) {
    return this.data[name];
  }
}

let user = {
  name: "apple",
  desc: "user",
  key: Symbol("用户资料"),
};

let cart = {
  name: "apple",
  desc: "cart",
  key: Symbol("购物车资料"),
};

Cache.set(user.key, user);
Cache.set(cart.key, cart);
console.log(Cache.get(user.key));

let symbol = Symbol("这是一个symbol模型");
let hd1 = {
  name: "jason",
  [symbol]: "houdunren.com",
};

for (const key of Object.getOwnPropertySymbols(hd1)) {
  console.log(key);
}

for (const key of Reflect.ownKeys(hd1)) {
  console.log(key);
}

let site = Symbol("这是一个Symbol");
class User {
  constructor(name) {
    this.name = name;
    this[site] = "后盾人";
  }
  getName() {
    return `${this[site]} + ${this.name}`;
  }
}

let lisi = new User("李四");
for (const key in lisi) {
  // this[site] 是一个Symbol属性，被保护起来的，所以遍历不到它
  console.log(key);
}
